<?php

session_start();

require_once ("../../../db.php");


if (!isset($_SESSION['uid']) || ($_SESSION['type'] != 'student')) {
    die('Not logged in as an student user');
}

// this change the priority of the requests that the group have
$sql = 'SELECT * FROM groupparticipants WHERE participantid="' . $_SESSION['uid'] . '"';
$sth = $db->prepare($sql);
$sth->execute();
$group = $sth->fetchAll();      // select group ID
if ($group) {    
        $sql = 'UPDATE projectrequest SET priority=? WHERE projectid=? AND groupid=?'; // updates the group priority
        $sth = $db->prepare($sql);
        $sth->execute(array($_POST['priority'], $_POST['projects'], $group[0][0]));
        echo json_encode($group);
} else {
    echo json_encode(array('error' => 'Du er ikke i noen gruppe!'));
}
